@using k8s.Models
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@if (Endpoints != null && Endpoints.Count > 0)
{
    <Divider Orientation="left" Style="font-weight:bold">@Title</Divider>


    <HTable>
        <HTr>
            <HTd>IP</HTd>
            <HTd>Zone</HTd>
            <HTd>Node</HTd>
            <HTd>Host</HTd>
            <HTd>Ref</HTd>
            <HTd>Condition</HTd>
        </HTr>
        @foreach (var a in Endpoints)
        {
            <HTr>
                <HTd>@(string.Join(", ", a.Addresses))</HTd>
                <HTd>
                    @if (a.Zone != null)
                    {
                        <span>@($"zone={a.Zone}")</span>
                    }
                    @if (a.Hints != null && a.Hints.ForZones.Count > 0)
                    {
                        @foreach (var z in a.Hints.ForZones)
                        {
                            <span>@($"ForZone:{z.Name}")</span>
                        }
                    }
                </HTd>
                <HTd>@a.NodeName</HTd>
                <HTd>@a.Hostname</HTd>
                <HTd>
                    <RefView Ref="@a.TargetRef" ></RefView>
                </HTd>
                <HTd>

                    @if (a.Conditions?.Serving is true)
                    {
                        <Tag color="green">Serving</Tag>
                    }
                    @if (a.Conditions?.Ready is true)
                    {
                        <Tag color="green">Ready</Tag>
                    }
                    @if (a.Conditions?.Terminating is true)
                    {
                        <Tag color="red">Terminating</Tag>
                    }
                </HTd>
            </HTr>
        }
    </HTable>
}

@code {

    [Parameter]
    public IList<V1Endpoint> Endpoints { get; set; }

    [Parameter]
    public string Title { get; set; }

}
